#ifndef _STEPHEN_F_DUMAS_GLINSTRUCTIONS_H
#define _STEPHEN_F_DUMAS_GLINSTRUCTIONS_H

#include "driver.h"
#include "textbox.h"
#include "glstar.h"
#include "gltext.h"



GAMESTATE displayInstructionsPage()
{
//---------------Read in Instructions---------------------//
	ifstream fopen;
	fopen.open("Instructions.txt");
	string input;
	vector <string> text;

	while(!fopen.eof())
	{
		getline(fopen,input,'\n');
		text.push_back(input);
	}

	fopen.close();
//-------------------------------------------------------//

	glClearColor(0.0,0.0,0.0,0.0);
	
	glDisable(GL_DEPTH_TEST);	
	glDisable(GL_LIGHTING);
	glDisable(GL_BLEND);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluOrtho2D(0,X_DIM,Y_DIM,0);

	textBox* t = new textBox(100,510,120," Continue");

	float r = 0.2,g = 0.2,b = 0.2;
	int mult = 5;

	Star_C belt;
	belt.set2Dstars(2000);

	Timer fps;
	SDL_Event event;
	while(true)
	{
		fps.start();

		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		for(int i = 0; i < belt.NOS(); ++i)
		{
			if(i % 2 == 0)		{glColor4f(r, g, b, 0.9);}
			else				{glColor4f(1-r, 1-g, 1-b, 0.9);}

			glTranslatef(belt.sx(i),belt.sy(i),belt.sz(i));
			glutSolidSphere(belt.ss(i),10,10);
			glTranslatef(-belt.sx(i),-belt.sy(i),-belt.sz(i));
		}

		glLineWidth(8);
		glColor4f(0.5-r,0.5-g,0.5-b,1.0);
		writeText(0,200,1.1,1.8,"Instructions");
		glLineWidth(3.2);
		glColor4f(1-r,1-g,1-b,1.0);
		writeText(102,147,0.5,0.5,"Instructions");
		glColor4f(r,g,b,1.0);
		writeText(100,150,0.5,0.5,"Instructions");
		glLineWidth(1.0);
		glColor4f(1,1,1,1.0);
		writeText(125,170,0.1,0.1,"by the Mogs of War");
		writeText(0,600,0.1,0.1,"2007 Texas Tech University Computer Science");

		writeText(100,200,0.1,0.1,12,text);

		
		r += (0.001 * mult);
		g += (0.001 * mult);
		b += (0.001 * mult);

		if((r > 1)||(g > 1)||(b > 1)) mult = mult * -1;
		if((r < 0.2)||(g < 0.2)||(b < 0.2)) mult = mult * -1;

		t->draw();

		string temp;

		glLineWidth(1.0);
		glColor4f(1,1,1,1.0);
		

		SDL_GL_SwapBuffers();

		if(t->getData() == 1)
			return TITLE;

		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_KEYDOWN)
			{
				switch(event.key.keysym.sym)
				{
					case SDLK_RETURN:
					case SDLK_c:
					case SDLK_q:
					case SDLK_ESCAPE: return TITLE; break;
				}
			}
			if(event.type == SDL_MOUSEBUTTONDOWN)
			{
				if(t->clicked(event.button.x, event.button.y))
					{t->onClick();}
			}
			if(event.type == SDL_MOUSEMOTION)
			{
				t->setHover(t->hover(event.motion.x,event.motion.y));
			}
		}

		// Cap Frame Rate
		while(fps.get_ticks()<1000/35){}
	}
}

#endif